package com.shangma.cn.commons.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 开发人员: 辉哥真球帅
 * 联系方式: zhengzhoudaxuevip@163.com
 * 创建时间: 2021/10/13  11:43
 * 文件含义:
 */
@Configuration
public class SpringContainerUtils implements ApplicationContextAware {

    public static ApplicationContext applicationContext1;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        applicationContext1 = applicationContext;
    }


    /**
     * 获取容器中的Bean
     */

    public static <T> T getBean(Class<T> clazz) {
        return applicationContext1.getBean(clazz);
    }
}
